package com.xw.unification.constant;

import com.xw.unification.enums.SortType;
import org.springframework.http.HttpStatus;

import java.nio.charset.StandardCharsets;

public class UnificationConstant {

    public static final HttpStatus DEFAULT_ERROR_STATUS = HttpStatus.INTERNAL_SERVER_ERROR;

    public static final String CONFIG_PROPERTY_KEY_PREFIX = "web.unification-config.";

    /**
     * 统一配置开关默认状态
     */
    public static final boolean DEFAULT_ENABLE = true;

    /**
     * 统一配置开关 property key
     */
    public static final String ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "enable";

    /**
     * API version 配置开关默认状态
     */
    public static final boolean DEFAULT_API_VERSION_ENABLE = false;

    /**
     * API version 配置开关 property key
     */
    public static final String API_VERSION_ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "api-version.enable";

    /**
     * 统一响应体配置开关默认状态
     */
    public static final boolean DEFAULT_UNIFIED_RESPONSE_ENABLE = false;

    /**
     * 统一响应体配置开关 property key
     */
    public static final String UNIFIED_RESPONSE_ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "unified-response.enable";

    /**
     * 统一异常处理响应体配置开关默认状态
     */
    public static final boolean DEFAULT_UNIFIED_EXCEPTION_ENABLE = false;

    /**
     * 统一异常处理配置开关 property key
     */
    public static final String UNIFIED_EXCEPTION_ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "unified-exception.enable";

    public static class SignatureCheckConstant {

        /**
         * 统一验签处理响应体配置开关默认状态
         */
        public static final boolean DEFAULT_API_SIGNATURE_ENABLE = false;

        /**
         * 统一验签处理配置开关 property key
         */
        public static final String API_SIGNATURE_ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "api-signature-check.enable";

        /**
         * 默认是否全局检验
         */
        public static final boolean DEFAULT_GLOBAL_CHECK = false;

        /**
         * 默认是否全局检验
         */
        public static final String DEFAULT_CHARSET_NAME = StandardCharsets.UTF_8.name();

        /**
         * 默认是否有签名 key
         */
        public static final boolean DEFAULT_HAS_SIGNATURE_KEY = true;

        /**
         * 默认签名 key 是否参与排序
         */
        public static final boolean DEFAULT_SIGNATURE_KEY_IN_SORT = false;

        /**
         * 待验签名参数名 property key
         */
        public static final String DEFAULT_SIGNATURE_KEY_NAME = "key";

        /**
         * 待验签名参数名 property key
         */
        public static final String DEFAULT_VALIDATION_SIGNATURE_NAME = "signature";

        /**
         * 待验签名参数名 property key
         */
        public static final boolean DEFAULT_IGNORE_EMPTY_VALUE = true;

        public static final int DEFAULT_SIGNATURE_CHECK_ERROR_CODE = HttpStatus.FORBIDDEN.value();

        public static final SortType DEFAULT_SIGNATURE_PARAM_NAME_CHECK_SORT = SortType.ASC;

    }

    /**
     * 可重复读取 request body 配置常量
     */
    public static class RepeatableRequest {

        /**
         * API version 配置开关默认状态
         */
        public static final boolean DEFAULT_ENABLE = false;

        /**
         * API version 配置开关 property key
         */
        public static final String ENABLE_PROPERTY_KEY = CONFIG_PROPERTY_KEY_PREFIX + "request-body-repeatable-read.enable";

        /**
         * API version 配置开关 property key
         */
        public static final boolean DEFAULT_ALLOW_NO_CONTENT_TYPE = true;

        /**
         * API version 配置开关 property key
         */
        public static final boolean DEFAULT_SKIP_IF_CONTENT_LENGTH_OVER_INT = true;

    }

}
